<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>删除一个元素</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="memcached.decrementbykey.html">« Memcached::decrementByKey</a></li>
      <li style="float: right;"><a href="memcached.deletebykey.html">Memcached::deleteByKey »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.memcached.html">Memcached</a></li>
    <li>删除一个元素</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="memcached.delete" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcached::delete</h1>
  <p class="verinfo">(PECL memcached &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Memcached::delete</span> &mdash; <span class="dc-title">删除一个元素</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcached.delete-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Memcached::delete</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$time</code><span class="initializer"> = 0</span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>Memcached::delete()</strong></span>从服务端删除<code class="parameter">key</code>对应的元素.
   参数<code class="parameter">time</code>是一个秒为单位的时间(或一个UNIX时间戳表明直到那个时间), 用来表明
   客户端希望服务端在这段时间拒绝对这个key的<code class="literal">add</code>和<code class="literal">replace</code>命令.
   由于这个时间段的存在, 元素被放入一个删除队列, 表明它不可以通过<code class="literal">get</code>命令获取到值, 但是同时
   <code class="literal">add</code>和<code class="literal">replace</code>命令也会失败(无论如何<code class="literal">set</code>命令都会成功).
   在这段时间过去后, 元素最终被从服务端内存删除.<code class="parameter">time</code>参数默认0(表明元素会被立即删除并且之后对这个
   key的存储命令也会成功).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-memcached.delete-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">key</code></dt>

     <dd>

      <p class="para">
       要删除的key
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">time</code></dt>

     <dd>

      <p class="para">
      服务端等待删除该元素的总时间(或一个Unix时间戳表明的实际删除时间).
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcached.delete-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
   如果key不存在, <span class="methodname"><a href="memcached.getresultcode.html" class="methodname">Memcached::getResultCode()</a></span>将会返回<strong><code>Memcached::RES_NOTFOUND</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcached.delete-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4386">
    <p><strong>示例 #1 <span class="function"><strong>Memcached::delete()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">delete</span><span style="color: #007700">(</span><span style="color: #DD0000">'key1'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-memcached.delete-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="memcached.deletebykey.html" class="methodname" rel="rdfs-seeAlso">Memcached::deleteByKey()</a> - 从指定的服务器删除一个元素</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>